﻿using System;
using System.Windows;
using System.Windows.Controls;
using SilverSynth.Library;

namespace SilverSynth.DemoUI
{
    public partial class OscillatorControl : UserControl
    {

        public OscillatorControl()
        {
            InitializeComponent();
        }


        public string Title
        {
            get { return this.title.Text; }
            set { this.title.Text = value; }
        }

        public ISignalChainComponent Output
        {
            get;
            private set;
        }

        public double Frequency
        {
            get { return this.hzSlider.Value; }
            set { this.hzSlider.Value = value; }
        }

        public short Pan
        {
            get { return (short)this.panSlider.Value; }
            set { this.panSlider.Value = value; }
        }

        public double FrequencyModulationFrequency
        {
            get { return this.hzModHzSlider.Value; }
            set { this.hzModHzSlider.Value = value; }
        }

        public short FrequencyModulationAmplitude
        {
            get { return (short)this.hzModAmpSlider.Value; }
            set { this.hzModAmpSlider.Value = value; }
        }

        public double AmplitudeModulationFrequency
        {
            get { return this.ampModSlider.Value; }
            set { this.ampModSlider.Value = value; }
        }

        public double Attenuation
        {
            get { return this.attenuationSlider.Value; }
            set { this.attenuationSlider.Value = value; }
        }

        public string WaveForm
        {
            get { return (string)this.waveFormCombo.SelectedItem; }
            set
            {
                this.waveFormCombo.SelectedItem = value;
            }
        }

        public void LoadOscillator(Mixer mixer)
        {
            Attenuator attenuator =
                Oscillator.Create(440)
                   .SetWaveForm(this.waveFormCombo, ComboBox.SelectedItemProperty)
                   .SetFrequency(this.hzSlider, Slider.ValueProperty)
                   .FrequencyModulate(
                       this.hzModHzSlider, Slider.ValueProperty,
                       this.hzModAmpSlider, Slider.ValueProperty)
                   .AmplitudeModulate(this.ampModSlider, Slider.ValueProperty)
                   .Pan(this.panSlider, Slider.ValueProperty)
                   .Attenuate(this.attenuationSlider, Slider.ValueProperty);
            this.Output = attenuator;
            attenuator.SendToMixer(mixer);
        }

        private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
        {
            if (this.RemoveClicked != null)
                this.RemoveClicked(this, EventArgs.Empty);
        }

        public event EventHandler RemoveClicked;

        private void WaveFormChanged(object sender, SelectionChangedEventArgs e)
        {
            Console.WriteLine("asdf");
        }
    }
}